<?php
namespace App\Service\BMR\Metabolize;

abstract class Person implements PersonInterface {
    //基础热量
    public $baseHot = 0;
    //年龄/年
    public $age = 0;
    //年龄系数
    public $ageRatio = 0;
    //体重kg
    public $weight = 0;
    //体重系数
    public $weightRatio = 0;
    //身高cm
    public $height = 0;
    //身高系数
    public $heightRatio = 0;

    public function __call($name, $value)
    {
        $pattern = '/^set(.+?)$/';
        if (preg_match($pattern, $name))
        {
            $name = preg_replace($pattern, '\1', $name);
            $field = strtolower($name);
            if (isset($this->{$field}))
            {
                $this->{$field} = $value[0];
            }
        }
        return $this;
    }

    public function __get($name)
   {
       if (isset($this->{$name}))
       {
           return $this->{$name};
       }
       throw new \Exception(__CLASS__.' 无法找到属性: '.$name, 400);
   }
}